package online.shenjian.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnProperty(name = "spring.rabbitmq.enable", matchIfMissing = true)
public class DirectExchangeConfig {

    @Bean
    public DirectExchange direct() {
        return new DirectExchange("direct");
    }

    private static class ConsumerConfig {

        @Bean
        public Queue directAutoDeleteQueue1() {
            return new AnonymousQueue();
        }

        @Bean
        public Queue directAutoDeleteQueue2() {
            return new AnonymousQueue();
        }

        @Bean
        public Binding directBinding1(DirectExchange direct, Queue directAutoDeleteQueue1) {
            return BindingBuilder.bind(directAutoDeleteQueue1).to(direct).with("orange");
        }

        @Bean
        public Binding directBinding2(DirectExchange direct, Queue directAutoDeleteQueue2) {
            return BindingBuilder.bind(directAutoDeleteQueue2).to(direct).with("black");
        }

        @Bean
        public Binding directBinding3(DirectExchange direct, Queue directAutoDeleteQueue2) {
            return BindingBuilder.bind(directAutoDeleteQueue2).to(direct).with("green");
        }
    }
}
